package com.wms.shop.controller;

import java.util.List;
import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.common.core.web.page.TableDataInfo;
import com.wms.common.security.annotation.PreAuthorize;
import com.wms.shop.domain.Banner;
import com.wms.shop.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 首页banner图Controller
 *
 * @author zzm
 * @date 2021-12-05
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController
{
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询首页banner图列表
     */
    @PreAuthorize(hasPermi = "shop:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(Banner banner)
    {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }


    /**
     * 获取首页banner图详细信息
     */
    @PreAuthorize(hasPermi = "shop:banner:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bannerService.selectBannerById(id));
    }

    /**
     * 新增首页banner图
     */
    @PreAuthorize(hasPermi = "shop:banner:add")
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody Banner banner)
    {
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改首页banner图
     */
    @PreAuthorize(hasPermi = "shop:banner:edit")
    @PostMapping(value = "update")
    public AjaxResult edit(@RequestBody Banner banner)
    {
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除首页banner图
     */
    @PreAuthorize(hasPermi = "shop:banner:remove")
    @PostMapping(value = "delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bannerService.deleteBannerByIds(ids));
    }
}